home *** CD-ROM | disk | FTP | other *** search
/ Aminet 1 (Walnut Creek) / Aminet - June 1993 [Walnut Creek].iso / aminet / biz / dbase / dfa12.lha / rexx / insert_adrletter.ced < prev    next >
Text File  |  1993-04-24  |  5KB  |  248 lines

  1. /************************************************************************
  2.  *
  3.  * insert_adrletter.ced                by Dirk Federlein 1993
  4.  *
  5.  * Inserts an address into an already done letter head.
  6.  
  7.  * You may use the following fill-ins, when creating your
  8.  * letter head template:
  9.  *     - <Date>
  10.  *     - <Address>
  11.  *     - <First>
  12.  *     - <Name>
  13.  *     - <Street>
  14.  *     - <ZIP>
  15.  *     - <City>
  16.  *     - <Country>
  17.  *
  18.  * You may write the part of the desired address anywhere to the
  19.  * letter head template. It is deleted by the script, before the
  20.  * parts of the address are inserted!
  21.  *
  22.  * Up to now every item may occur up to three times. This limit is
  23.  * done because of a bug (?) in CEDs Arexx-Port the
  24.  * __global__ replace does not work and a walk around had to be
  25.  * found! If YOU find another way of doing multiple replaces, please
  26.  * send me the modified script, so I can include it into the
  27.  * distribution --- Thanx.
  28.  *
  29.  * Lookup part taken from:
  30.  *
  31.  * LookUp.ced                         Copyright (c) 1989, Peter Cherna
  32.  *
  33.  * ARexx program for CygnusEd Professional that looks up the word under
  34.  * the cursor.
  35.  *
  36.  * Version 1.30:  August 20, 1989        Release 1.2:  August 29, 1989
  37.  *
  38.  ************************************************************************/
  39.  
  40. options results
  41.  
  42. address 'rexx_ced'
  43.  
  44. tabchar = '09'X
  45. cr    = '0A'X
  46. /*    Get contents of current line: */
  47. status 55
  48. line = result
  49.  
  50. /*    Get tab size: */
  51. status 8
  52. tabadjust = result - 1
  53.  
  54. /*    Get cursor x position (relative to beginning of line = 1): */
  55. status 46
  56. cur = result + 1
  57.  
  58. i = index(line,tabchar)
  59. DO while i > 0 & i <= cur - tabadjust
  60.     cur = cur - tabadjust
  61.     i = index(line,tabchar,i+1)
  62. END
  63.  
  64. /*    If the current character is non-alphabetic, then start one character
  65.     over to the left.  This allows the cursor to be immediately after
  66.     the key word (say on a space or bracket.) */
  67.  
  68. char = substr(line,cur,1)
  69. if (~(datatype(char,'A') | char = '_') & cur > 1) then
  70.     cur = cur - 1
  71.  
  72. /*    Find leftmost and rightmost alphabetic character adjacent to current: */
  73.  
  74. right = cur - 1
  75. left = cur + 1
  76. char = 'A'
  77. DO while (datatype(char,'A') | char = '_') & (left > 0)
  78.      left = left - 1
  79.     if left > 0 then
  80.         char = substr(line,left,1)
  81. END
  82. char = 'A'
  83. DO while (datatype(char,'A') | (char = '_'))
  84.     right = right + 1
  85.     char = substr(line,right,1)
  86. END
  87.  
  88. if right-left <= 1 then
  89. DO
  90.     getstring
  91.     target = result
  92.     if (target = 'RESULT') then
  93.         exit
  94. END
  95. else
  96. DO
  97.     target = substr(line,left+1,right-left-1)
  98.     newtarget = '*'target'*'
  99. END
  100.  
  101.  
  102. DO
  103.     say 'Searching for address' newtarget '...'
  104.  
  105.     if ~show(ports, DFA) then
  106.     do
  107.         'okay1' 'You should have DFA running, if you' cr 'want to get an address from it!'
  108.         exit 0
  109.     end
  110.  
  111.  
  112.     address 'DFA' "SEARCH" newtarget "IGNORECASE FIELDS=ALL STEM ADR."
  113.  
  114.     if rc=0 then
  115.     do
  116.         "Prev WORD"
  117.         "Mark BLOCK"
  118.         "NEXT WORD"
  119.         "CUT BLOCK"
  120.  
  121.         "Beg of File"
  122.  
  123.         "Replace" '<Address>' ADR.ADDRESS.0
  124.         "Replace" '<Address>' ADR.ADDRESS.0
  125.         "Replace" '<Address>' ADR.ADDRESS.0
  126.  
  127.         "Beg of File"
  128.  
  129.         "Replace" '<First>' ADR.ADDRESS.2
  130.         "Replace" '<First>' ADR.ADDRESS.2
  131.         "Replace" '<First>' ADR.ADDRESS.2
  132.  
  133.         "Beg of File"
  134.  
  135.         Replace '<Name>' ADR.ADDRESS.1
  136.         Replace '<Name>' ADR.ADDRESS.1
  137.         Replace '<Name>' ADR.ADDRESS.1
  138.  
  139.         "Beg of File"
  140.  
  141.         Replace '<Street>' ADR.ADDRESS.3
  142.         Replace '<Street>' ADR.ADDRESS.3
  143.         Replace '<Street>' ADR.ADDRESS.3
  144.  
  145.         "Beg of File"
  146.  
  147.         Replace '<ZIP>' ADR.ADDRESS.4
  148.         Replace '<ZIP>' ADR.ADDRESS.4
  149.         Replace '<ZIP>' ADR.ADDRESS.4
  150.  
  151.         "Beg of File"
  152.  
  153.         Replace '<City>' ADR.ADDRESS.5
  154.         Replace '<City>' ADR.ADDRESS.5
  155.         Replace '<City>' ADR.ADDRESS.5
  156.  
  157.         "Beg of File"
  158.  
  159.         Replace '<Country>' ADR.ADDRESS.6
  160.         Replace '<Country>' ADR.ADDRESS.6
  161.         Replace '<Country>' ADR.ADDRESS.6
  162.  
  163.  
  164.         "Beg of File"
  165.  
  166.         /* Get date */
  167.         address command 'c:date > ' 'ram:tmp_date'
  168.  
  169.         /* Clear Date */
  170.         Replace '<Date>' ""
  171.  
  172.         /* Insert Date from temporary file */
  173.         include file "ram:tmp_date"
  174.  
  175.         /* Delete all stuff from date string that */
  176.         /* is not wanted */
  177.         "Mark block"
  178.         "Next word"
  179.         "Cut block"
  180.         "text" ' '
  181.  
  182.         "Next word"
  183.         "Next word"
  184.         "Next word"
  185.         "Next word"
  186.         "Next word"
  187.  
  188.         "Delete to EOL"
  189.  
  190.         /* Get date */
  191.         address command 'c:date > ' 'ram:tmp_date'
  192.  
  193.         /* Clear Date */
  194.         Replace '<Date>' ""
  195.  
  196.         /* Insert Date from temporary file */
  197.         include file "ram:tmp_date"
  198.  
  199.         /* Delete all stuff from date string that */
  200.         /* is not wanted */
  201.         "Mark block"
  202.         "Next word"
  203.         "Cut block"
  204.         "text" ' '
  205.  
  206.         "Next word"
  207.         "Next word"
  208.         "Next word"
  209.         "Next word"
  210.         "Next word"
  211.  
  212.         "Delete to EOL"
  213.  
  214.         /* Get date */
  215.         address command 'c:date > ' 'ram:tmp_date'
  216.  
  217.         /* Clear Date */
  218.         Replace '<Date>' ""
  219.  
  220.         /* Insert Date from temporary file */
  221.         include file "ram:tmp_date"
  222.  
  223.         /* Delete all stuff from date string that */
  224.         /* is not wanted */
  225.         "Mark block"
  226.         "Next word"
  227.         "Cut block"
  228.         "text" ' '
  229.  
  230.         "Next word"
  231.         "Next word"
  232.         "Next word"
  233.         "Next word"
  234.         "Next word"
  235.  
  236.         "Delete to EOL"
  237.  
  238.         /* Delete temporary date file */
  239.         address command 'c:delete ' 'ram:tmp_date'
  240.  
  241.  
  242.     end
  243.     else
  244.         'okay1' 'Could not find address of' newtarget '! '
  245. END
  246.  
  247. exit
  248.